package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Flower;
import com.ruoyi.system.service.IFlowerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 花店Controller
 *
 * @author zzn
 * @date 2025-01-16
 */
@RestController
@RequestMapping("/system/flower")
public class FlowerController extends BaseController
{
    @Autowired
    private IFlowerService flowerService;

    /**
     * 查询花店列表
     */
    @PreAuthorize("@ss.hasPermi('system:flower:list')")
    @GetMapping("/list")
    public TableDataInfo list(Flower flower)
    {
        startPage();
        List<Flower> list = flowerService.selectFlowerList(flower);
        return getDataTable(list);
    }

    /**
     * 导出花店列表
     */
    @PreAuthorize("@ss.hasPermi('system:flower:export')")
    @Log(title = "花店", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Flower flower)
    {
        List<Flower> list = flowerService.selectFlowerList(flower);
        ExcelUtil<Flower> util = new ExcelUtil<Flower>(Flower.class);
        util.exportExcel(response, list, "花店数据");
    }

    /**
     * 获取花店详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:flower:query')")
    @GetMapping(value = "/{flowerId}")
    public AjaxResult getInfo(@PathVariable("flowerId") Long flowerId)
    {
        return success(flowerService.selectFlowerByFlowerId(flowerId));
    }

    /**
     * 新增花店
     */
    @PreAuthorize("@ss.hasPermi('system:flower:add')")
    @Log(title = "花店", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Flower flower)
    {
        return toAjax(flowerService.insertFlower(flower));
    }

    /**
     * 修改花店
     */
    @PreAuthorize("@ss.hasPermi('system:flower:edit')")
    @Log(title = "花店", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Flower flower)
    {
        return toAjax(flowerService.updateFlower(flower));
    }

    /**
     * 删除花店
     */
    @PreAuthorize("@ss.hasPermi('system:flower:remove')")
    @Log(title = "花店", businessType = BusinessType.DELETE)
	@DeleteMapping("/{flowerIds}")
    public AjaxResult remove(@PathVariable Long[] flowerIds)
    {
        return toAjax(flowerService.deleteFlowerByFlowerIds(flowerIds));
    }
}
